#include <bits/stdc++.h>
#include <opencv2/opencv.hpp>

using namespace std;

vector<cv::Mat> T;

vector<int> show_predict(cv::Mat img)
{
    vector<int> N = {0, 0, 0, 0, 0};
    for (int i = 0; i < 5; i++)
    {
        for (int x = 0; x < 480; x++)
        {
            for (int y = 0; y < 640; y++)
            {
                if (T[i].at<cv::Vec3d>(x, y)[1] == 200 && img.at<uint8_t>(x, y) == 255)
                {
                    N[i]++;
                }
            }
        }
    }
    return N;
}

int main()
{
    T.push_back(cv::imread("/home/libtity/car_cv/ Cpp/l2_hight.jpg"));
    T.push_back(cv::imread("/home/libtity/car_cv/ Cpp/l1_hight.jpg"));
    T.push_back(cv::imread("/home/libtity/car_cv/ Cpp/m_hight.jpg"));
    T.push_back(cv::imread("/home/libtity/car_cv/ Cpp/r1_hight.jpg"));
    T.push_back(cv::imread("/home/libtity/car_cv/ Cpp/r2_hight.jpg"));

    cv::VideoCapture camera = cv::VideoCapture(0);
    cv::Mat img;
    while (1)
    {
        camera.read(img);
        cv::imshow("img", img);
        cv::Mat kernel = cv::getStructuringElement(0, cv::Size(5, 5));
        cv::Mat img_erode;

        // 腐蚀，去除细小的杂乱光点
        erode(img, img_erode, kernel);
        imshow("img_erode", img_erode);

        // 边缘检测
        cv::Mat img_canny;
        Canny(img_erode, img_canny, 300, 400, 3, true);
        imshow("canny", img_canny);

        vector<int> N(5);
        for (auto i : N)
        {
            cout << i << " ";
        }
        cout << endl;

        char k = cv::waitKey(10);
        if (k == 'q')
        {
            break;
        }
    }

    cv::destroyAllWindows();

    return 0;
}